
import { loadInfoTeaaccessorialInfoInfo } from "../../../services/teacherSelf"
import { getUserNationInfo, loadBasePeopleListNoPage } from "../../../services/self"
import { stat } from "fs";
export default {

  namespace: 'teacherInformation',

  state: {
    user: "",
    nation: [],
    nationality: ""
  },

  effects: {
    *getUserInfo({ payload }, { call, put }) {
      let { data } = yield loadInfoTeaaccessorialInfoInfo(payload)
      data.peopleCode = [data.peopleCode]
      data.genderCode = ["","男","女"][data.genderCode]
      data.marryState = ["否","是"][data.marryState]
      data.nationCode = [data.nationCode]
      data.cardTypeCode = ["","中华人民共和国居民身份证","军人证件","港澳台身份证","护照","华侨身份证"][parseInt(data.cardTypeCode)]
      yield put({
        type: 'save', payload: data
      });
    },
    *getUserNation({ payload }, { call, put }) {
      let nav = yield getUserNationInfo(payload)
      yield put({
        type: 'changeNation', payload: [nav.map(s => {
          return {
            ...s,
            label: s.name,
            value: s.code
          }
        })]
      });
    },
    //获取民族列表
    *loadBasePeopleList({ payload }, { call, put }) {
      let nav = yield loadBasePeopleListNoPage(payload)
      yield put({
        type: 'changeNationality',
        payload: [nav.map(s => {
          return {
            ...s,
            label: s.name,
            value: s.code
          }
        })]
      });

    },

    *fetch({ payload }, { call, put }) {  // eslint-disable-line
      yield put({ type: 'save' });
    },
  },

  reducers: {
    save(state, { payload }) {
      state.user = payload;
      return { ...state, ...payload };
    },
    changeNation(state, { payload }) {
      state.nation = payload;
      return {
        ...state,
        ...payload,
      }
    },
    changeNationality(state, { payload }) {
      state.nationality = payload;
      return {
        ...state,
        ...payload,
      }
    },
  },

};
